/*
@Time : 2022/5/28 22:41
@Author : gaozhichang
@File : client.go
@des: GoLand
*/
package main

import (
	"context"
	"fmt"
	hello "github.com/gaozhichang/golang-study/grpcdemo/proto"
	"google.golang.org/grpc"
	"google.golang.org/grpc/grpclog"
)

func main() {
	// 连接rpc通道
	conn, err := grpc.Dial("localhost:8062", grpc.WithInsecure())
	if err != nil {
		grpclog.Fatalln(err)
	}
	defer conn.Close()

	// 初始化客户端
	cli := hello.NewHelloClient(conn)

	// 调用方法
	reqBody := &hello.HelloRequest{Name: "world"}
	res, err := cli.SayHello(context.Background(), reqBody)
	if err != nil {
		grpclog.Fatalln(err)
	}

	fmt.Println(res.Message)
}
